package com.yaDuo.common.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.yaDuo.common.base.BaseFragment
import com.yaDuo.common.util.VBUtil

abstract class BaseVBFragment<VB : ViewBinding?> : BaseFragment() {
    protected var vb: VB? = null
    private var view: View? = null

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        if (vb == null) {
            vb =
                VBUtil.createViewBindingFromGenericSuperclass(javaClass, inflater, container, false)
            view = vb!!.root
            onInit()
        }
        onObserve()
        return view
    }

    protected abstract fun onInit()

    protected abstract fun onObserve()
}